﻿//编辑对话框
var dlg = new MyAppDialog(600, 400);//关闭对话框
function closeDialog(reload) {
    dlg.close();

    if (reload)
        $("#datagrid").treegrid("reload");
}

var cols = [[
    { field: "Id", title: 'Id', width: 10, hidden: true },
    { field: "Eval_deptname", title: '车间名称', sortable: false, width: 200, align: 'left' },
    { field: "Requireusers", title: '要求测评人数', sortable: false, width: 120, align: 'center' },
    { field: "Finishedusers", title: '已完成人数', sortable: false, width: 120, align: 'center' },
    { field: "Rate", title: '完成率', sortable: false, width: 120, align: 'center' },
    { field: "Updatetime", title: '最后提交时间', sortable: false, width: 130, align: 'left' }
]];

$(document).ready(function () {
    //导出
    $("#btnexport").click(function (evt) {
        evt.preventDefault();

        exportFile();
    });

    $("#btnselectyear").click(function (evt) {
        evt.preventDefault();
        dlg.setSize(700, 460);
        dlg.setURL("选择测评年度", baseurl + "Public/EvalSelect?callback=onEvalSelected");
        dlg.show();
    })

    LoadDatagrid();
});

function onEvalSelected(data) {
    var json = JSON.parse(data);
    location.href = baseurl + "Report/OfficeMemberResult/Index/" + json.EvaluateYear;
}

//加载列表数据
function LoadDatagrid() {
    var $dg = $("#datagrid");
    $dg.treegrid({
        title: '',
        url: baseurl + 'Report/OfficeMemberResult/ReportResultJson',
        fit: true,
        fitColumns: false,
        animate: true,
        striped: true,
        nowrap: true,
        lines: false,
        idField: 'id',
        treeField: 'Eval_deptname',
        //pagination: false,
        //pageNumber: 1,
        //pageSize: 20,
        //pageList: [10, 20, 30, 45, 60, 75],
        //rownumbers: true,
        singleSelect: true,
        queryParams: {
            evalId: $("#evalId").val()
        },
        //sortName: 'Sort',
        //sortOrder: 'asc',
        columns: cols,
        onLoadSuccess: function (d,data) {
            //console.log(data);
            //多选时，加载完成后清除所有选中项（不然可能会有残留选中项）
            $dg.datagrid("clearSelections");
        },
        rowStyler: function (row) {
            if (row.level == "2") {
                return "background-color:#ffffb5;";
            }
        }
    });
}

//导出
function exportFile() {
    var sort = $("#datagrid").datagrid('options').sortName;
    var order = $("#datagrid").datagrid('options').sortOrder;
    layer.msg("正在生成文件，请稍后...", { icon: 16, time: 0 });
    $.ajax({
        type: "post",
        url: baseurl + "Report/OfficeMemberResult/CreateExportFile",
        dataType: 'json',
        data: {
            evalId: $("#evalId").val(),
            sort: sort,
            order: order
        },
        success: function (e) {
            layer.closeAll();
            if (e.Ret == "0") {
                location.href = baseurl + "Report/OfficeMemberResult/DownFile?key=" + e.Content;
            } else {
                $.messager.alert("错误", e.Msg, "error");
            }
        },
        error: function (xhr) {
            showError(xhr);
        }
    });
}